******************************************************************************************************************************************************
*This do file produce tables in "Firm Growth and Corruption: Empirical Evidence from Vietnam"												   																	    *
******************************************************************************************************************************************************
clear all
set more off
set mem 600m
set maxvar 3000
set matsize 5000

version 

*SET DIRECTORY HERE*
global dir_data_original /Users/Jie/Dropbox (Personal)/CorruptionIncome/EJFinalSubmission/data&program/original raw data/
global dir_data_coded /Users/Jie/Dropbox (Personal)/CorruptionIncome/EJFinalSubmission/data&program/intermediary data/
global dir_data_analysis /Users/Jie/Dropbox (Personal)/CorruptionIncome/EJFinalSubmission/data&program/analysis data/

global dir_output_table /Users/Jie/Dropbox (Personal)/CorruptionIncome/EJFinalSubmission/tables/raw
global dir_output_figure /Users/Jie/Dropbox (Personal)/CorruptionIncome/EJFinalSubmission/figures

net set ado "/Users/Jie/Dropbox (Personal)/CorruptionIncome/EJFinalSubmission/data&program/ado files"
adopath + "/Users/Jie/Dropbox (Personal)/CorruptionIncome/EJFinalSubmission/data&program/ado files"

cap log close


********** Table 1: SUMMARY STATISTICS **********

set more off

use "${dir_data_analysis}/finalanalysissample_allfirms",clear

cap mat drop _all

g lnprem_temp=lnprem
replace lnprem_temp=. if pieces_d==1
foreach v in bribe_pctrev yrsopen employ_n  meanemploy_rjt lntotalemploy_rjt lnprem_temp ownland lurc_o ownlandnlc operations opdich sharedocs formerhhfirm formerSOE ownersoe govholdshare{
	sum `v',d
	mat S = nullmat(S)\ (int(r(N)) , round(r(p50),0.001), round(r(mean),0.001), round(r(sd),0.001))
}

tempname texfile
file open `texfile' using "${dir_output_table}/Table1a", write replace
file close `texfile'

estout matrix(S) using "${dir_output_table}/Table1a", label style(tex) collabels(none) eqlabels(none) append 


use "${dir_data_analysis}/finalanalysissample",clear

cap mat drop _all

drop if employ_lag==.b & employ==.b
keep if (employ_lag>2 & employ_lag!=.b) | (employ_lag==.b & employ>2 & yrsopen>0 & yrsopen!=.)

g lnprem_temp=lnprem
replace lnprem_temp=. if pieces_d==1
foreach v in bribe_pctrev yrsopen employ_n  meanemploy_rjt lntotalemploy_rjt lnprem_temp ownland lurc_o ownlandnlc operations opdich sharedocs formerhhfirm formerSOE ownersoe govholdshare{
	sum `v',d
	mat S = nullmat(S`i')\ (int(r(N)) , round(r(p50),0.001), round(r(mean),0.001), round(r(sd),0.001))
}

tempname texfile
file open `texfile' using "${dir_output_table}/Table1b", write replace
file close `texfile'

estout matrix(S) using "${dir_output_table}/Table1b", label style(tex) collabels(none) eqlabels(none) append 



********** Table 2: First Stage **********
 
set more off

use "${dir_data_analysis}/GSO_IV",clear

sort broad year

merge m:1 broad year using "${dir_data_original}/CH_YLS_0612"
keep if _m==3
drop _m

label var lntotalemploy_r_jt "Log Vietnamese employment in industry-year (excluding own province)"
label var lnchtotalemploy_jt "Log Chinese employment in industry-year"

xi: bencgmareg lntotalemploy_rjt lntotalemploy_r_jt i.t, absorb(rj) cluster1(r) cluster2(jt)
testparm lntotalemploy_r_jt
outreg2 using "${dir_output_table}/Table2", adds(F-stats,r(chi2)) tex(frag) se keep(lntotalemploy_r_jt) label replace

xi: bencgmareg lntotalemploy_rjt lnchtotalemploy_jt i.t, absorb(rj) cluster1(r) cluster2(jt)
testparm lnchtotalemploy_jt
outreg2 using "${dir_output_table}/Table2", adds(F-stats,r(chi2)) tex(frag) se keep(lnchtotalemploy_jt) label append


********** Table 3: Main Results **********
 
set more off

use "${dir_data_analysis}/finalanalysissample",clear

drop if employ_lag==.b & employ==.b
keep if (employ_lag>2 & employ_lag!=.b) | (employ_lag==.b & employ>2 & yrsopen>0 & yrsopen!=.)

***Vietnam

//Single IV
bencgmivreg bribe_pctrev i.t i.rj ,endog(lntotalemploy_rjt) instr(lntotalemploy_r_jt) cluster1(r) cluster2(jt)
outreg2 using "${dir_output_table}/Table3a", tex(frag) se keep(lntotalemploy_rjt) label replace

//Multiple IV
bencgmivreg bribe_pctrev i.t i.rj ,endog(lntotalemploy_rjt) instr(lntotalemploy_r_jtXinddummy1-lntotalemploy_r_jtXinddummy18) cluster1(r) cluster2(jt)
outreg2 using "${dir_output_table}/Table3a", tex(frag) se keep(lntotalemploy_rjt) label append

//Reduced form: OLS
xi: bencgmareg bribe_pctrev lntotalemploy_r_jt i.t , absorb(rj) cluster1(r) cluster2(jt)
outreg2 using "${dir_output_table}/Table3a", tex(frag) se keep(lntotalemploy_r_jt) label append

//Reduced form: Ordered probit
xi: bencgmoprobit bribe_pctrev lntotalemploy_r_jt i.t i.rj ,cluster1(r) cluster2(jt)
outreg2 using "${dir_output_table}/Table3a", tex(frag) se keep(lntotalemploy_r_jt) label append


***China

//Single IV
bencgmivreg bribe_pctrev i.t i.rj ,endog(lntotalemploy_rjt) instr(lnchtotalemploy_jt) cluster1(r) cluster2(jt)
outreg2 using "${dir_output_table}/Table3b", tex(frag) se keep(lntotalemploy_rjt) label replace

//Multiple IV
bencgmivreg bribe_pctrev i.t i.rj ,endog(lntotalemploy_rjt) instr(lnchtotalemploy_jtXinddummy1-lnchtotalemploy_jtXinddummy18) cluster1(r) cluster2(jt)
outreg2 using "${dir_output_table}/Table3b", tex(frag) se keep(lntotalemploy_rjt) label append

//Reduced form: OLS
xi: bencgmareg bribe_pctrev lnchtotalemploy_jt i.t , absorb(rj) cluster1(r) cluster2(jt)
outreg2 using "${dir_output_table}/Table3b", tex(frag) se keep(lnchtotalemploy_jt) label append

//Ordered probit
xi: bencgmoprobit bribe_pctrev lnchtotalemploy_jt i.t i.rj ,cluster1(r) cluster2(jt)
outreg2 using "${dir_output_table}/Table3b", tex(frag) se keep(lnchtotalemploy_jt) label append


	
********** Table 4: Heterogeneous Effects on Property Rights **********

set more off

use "${dir_data_analysis}/finalanalysissample",clear

drop if employ_lag==.b & employ==.b
keep if (employ_lag>2 & employ_lag!=.b) | (employ_lag==.b & employ>2 & yrsopen>0 & yrsopen!=.)

***Single VN IV

bencgmivreg bribe_pctrev lurclastyr i.t i.rj,endog(lntotalemploy_rjt lntotalemploy_rjtXlurclastyr) instr(lntotalemploy_r_jt lntotalemploy_r_jtXlurclastyr) cluster1(r) cluster2(jt)
outreg2 using "${dir_output_table}/Table4a", tex(frag) se keep(lntotalemploy_rjt lntotalemploy_rjtXlurclastyr) label replace

bencgmivreg bribe_pctrev i.t i.rj lurclastyr,endog(lntotalemploy_rjt lntotalemploy_rjtXlurclastyr lntotalemploy_rjtXlnemployj) instr(lntotalemploy_r_jt lntotalemploy_r_jtXlurclastyr lntotalemploy_r_jtXlnemployj) cluster1(r) cluster2(jt)
outreg2 using "${dir_output_table}/Table4a", tex(frag) se keep(lntotalemploy_rjt lntotalemploy_rjtXlurclastyr) label append

bencgmivreg bribe_pctrev ownland lurclastyr i.t i.rj,endog(lntotalemploy_rjt lntotalemploy_rjtXownland lntotalemploy_rjtXlurclastyr) instr(lntotalemploy_r_jt lntotalemploy_r_jtXownland lntotalemploy_r_jtXlurclastyr) cluster1(r) cluster2(jt)
outreg2 using "${dir_output_table}/Table4a", tex(frag) se keep(lntotalemploy_rjt lntotalemploy_rjtXlurclastyr lntotalemploy_rjtXownland) label append

bencgmivreg bribe_pctrev ownland lurclastyr i.t i.rj, endog(lntotalemploy_rjt lntotalemploy_rjtXownland lntotalemploy_rjtXlurclastyr lntotalemploy_rjtXlnemployj) instr(lntotalemploy_r_jt lntotalemploy_r_jtXownland lntotalemploy_r_jtXlurclastyr lntotalemploy_r_jtXlnemployj) cluster1(r) cluster2(jt)
outreg2 using "${dir_output_table}/Table4a", tex(frag) se keep(lntotalemploy_rjt lntotalemploy_rjtXlurclastyr lntotalemploy_rjtXownland) label append


***Multiple VN IV

bencgmivreg bribe_pctrev lurclastyr i.t i.rj, endog(lntotalemploy_rjt lntotalemploy_rjtXlurclastyr) instr(lntotalemploy_r_jtXinddummy1-lntotalemploy_r_jtXinddummy18 VNXlurclastyrXinddummy1-VNXlurclastyrXinddummy18) cluster1(r) cluster2(jt)
outreg2 using "${dir_output_table}/Table4a", tex(frag) se keep(lntotalemploy_rjt lntotalemploy_rjtXlurclastyr) label append

bencgmivreg bribe_pctrev lurclastyr i.t i.rj, endog(lntotalemploy_rjt lntotalemploy_rjtXlurclastyr lntotalemploy_rjtXlnemployj) instr(lntotalemploy_r_jtXinddummy1-lntotalemploy_r_jtXinddummy18 VNXlurclastyrXinddummy1-VNXlurclastyrXinddummy18 VNXlnemployjXinddummy1-VNXlnemployjXinddummy18) cluster1(r) cluster2(jt)
outreg2 using "${dir_output_table}/Table4a", tex(frag) se keep(lntotalemploy_rjt lntotalemploy_rjtXlurclastyr) label append

bencgmivreg bribe_pctrev ownland lurclastyr i.t i.rj,endog(lntotalemploy_rjt lntotalemploy_rjtXownland lntotalemploy_rjtXlurclastyr) instr(lntotalemploy_r_jtXinddummy1-lntotalemploy_r_jtXinddummy18 VNXownlandXinddummy1-VNXownlandXinddummy18 VNXlurclastyrXinddummy1-VNXlurclastyrXinddummy18) cluster1(r) cluster2(jt)
outreg2 using "${dir_output_table}/Table4a", tex(frag) se keep(lntotalemploy_rjt lntotalemploy_rjtXlurclastyr lntotalemploy_rjtXownland) label append

bencgmivreg bribe_pctrev ownland lurclastyr i.t i.rj,endog(lntotalemploy_rjt lntotalemploy_rjtXownland lntotalemploy_rjtXlurclastyr lntotalemploy_rjtXlnemployj) instr(lntotalemploy_r_jtXinddummy1-lntotalemploy_r_jtXinddummy18 VNXownlandXinddummy1-VNXownlandXinddummy18 VNXlurclastyrXinddummy1-VNXlurclastyrXinddummy18 VNXlnemployjXinddummy1-VNXlnemployjXinddummy18) cluster1(r) cluster2(jt)
outreg2 using "${dir_output_table}/Table4a", tex(frag) se keep(lntotalemploy_rjt lntotalemploy_rjtXlurclastyr lntotalemploy_rjtXownland) label append


***Single Chinese IV

bencgmivreg bribe_pctrev lurclastyr i.t i.rj,endog(lntotalemploy_rjt lntotalemploy_rjtXlurclastyr) instr(lnchtotalemploy_jt lnchtotalemploy_jtXlurclastyr) cluster1(r) cluster2(jt)
outreg2 using "${dir_output_table}/Table4b", tex(frag) se keep(lntotalemploy_rjt lntotalemploy_rjtXlurclastyr) label replace

bencgmivreg bribe_pctrev i.t i.rj lurclastyr,endog(lntotalemploy_rjt lntotalemploy_rjtXlurclastyr lntotalemploy_rjtXlnemployj) instr(lnchtotalemploy_jt lnchtotalemploy_jtXlurclastyr lnchtotalemploy_jtXlnemployj) cluster1(r) cluster2(jt)
outreg2 using "${dir_output_table}/Table4b", tex(frag) se keep(lntotalemploy_rjt lntotalemploy_rjtXlurclastyr) label append

bencgmivreg bribe_pctrev ownland lurclastyr i.t i.rj,endog(lntotalemploy_rjt lntotalemploy_rjtXownland lntotalemploy_rjtXlurclastyr) instr(lnchtotalemploy_jt lnchtotalemploy_jtXownland lnchtotalemploy_jtXlurclastyr) cluster1(r) cluster2(jt)
outreg2 using "${dir_output_table}/Table4b", tex(frag) se keep(lntotalemploy_rjt lntotalemploy_rjtXlurclastyr lntotalemploy_rjtXownland) label append

bencgmivreg bribe_pctrev ownland lurclastyr i.t i.rj, endog(lntotalemploy_rjt lntotalemploy_rjtXownland lntotalemploy_rjtXlurclastyr lntotalemploy_rjtXlnemployj) instr(lnchtotalemploy_jt lnchtotalemploy_jtXownland lnchtotalemploy_jtXlurclastyr lnchtotalemploy_jtXlnemployj) cluster1(r) cluster2(jt)
outreg2 using "${dir_output_table}/Table4b", tex(frag) se keep(lntotalemploy_rjt lntotalemploy_rjtXlurclastyr lntotalemploy_rjtXownland) label append

	
***Multiple Chinese IV

bencgmivreg bribe_pctrev lurclastyr i.t i.rj, endog(lntotalemploy_rjt lntotalemploy_rjtXlurclastyr) instr(lnchtotalemploy_jtXinddummy1-lnchtotalemploy_jtXinddummy18 chXlurclastyrXinddummy1-chXlurclastyrXinddummy18) cluster1(r) cluster2(jt)
outreg2 using "${dir_output_table}/Table4b", tex(frag) se keep(lntotalemploy_rjt lntotalemploy_rjtXlurclastyr) label append

bencgmivreg bribe_pctrev lurclastyr i.t i.rj, endog(lntotalemploy_rjt lntotalemploy_rjtXlurclastyr lntotalemploy_rjtXlnemployj) instr(lnchtotalemploy_jtXinddummy1-lnchtotalemploy_jtXinddummy18 chXlurclastyrXinddummy1-chXlurclastyrXinddummy18 chXlnemployjXinddummy1-chXlnemployjXinddummy18) cluster1(r) cluster2(jt)
outreg2 using "${dir_output_table}/Table4b", tex(frag) se keep(lntotalemploy_rjt lntotalemploy_rjtXlurclastyr) label append

bencgmivreg bribe_pctrev ownland lurclastyr i.t i.rj,endog(lntotalemploy_rjt lntotalemploy_rjtXownland lntotalemploy_rjtXlurclastyr) instr(lnchtotalemploy_jtXinddummy1-lnchtotalemploy_jtXinddummy18 chXownlandXinddummy1-chXownlandXinddummy18 chXlurclastyrXinddummy1-chXlurclastyrXinddummy18) cluster1(r) cluster2(jt)
outreg2 using "${dir_output_table}/Table4b", tex(frag) se keep(lntotalemploy_rjt lntotalemploy_rjtXlurclastyr lntotalemploy_rjtXownland) label append

bencgmivreg bribe_pctrev ownland lurclastyr i.t i.rj,endog(lntotalemploy_rjt lntotalemploy_rjtXownland lntotalemploy_rjtXlurclastyr lntotalemploy_rjtXlnemployj) instr(lnchtotalemploy_jtXinddummy1-lnchtotalemploy_jtXinddummy18 chXownlandXinddummy1-chXownlandXinddummy18 chXlurclastyrXinddummy1-chXlurclastyrXinddummy18 chXlnemployjXinddummy1-chXlnemployjXinddummy18) cluster1(r) cluster2(jt)
outreg2 using "${dir_output_table}/Table4b", tex(frag) se keep(lntotalemploy_rjt lntotalemploy_rjtXlurclastyr lntotalemploy_rjtXownland) label append


********** Table 5: Heterogeneous Effects on Operation Location **********

set more off

use "${dir_data_analysis}/finalanalysissample",clear

drop if employ_lag==.b & employ==.b
keep if (employ_lag>2 & employ_lag!=.b) | (employ_lag==.b & employ>2 & yrsopen>0 & yrsopen!=.)

****Single VN IV
bencgmivreg bribe_pctrev opdich i.t i.rj,endog(lntotalemploy_rjt lntotalemploy_rjtXopdich) instr(lntotalemploy_r_jt lntotalemploy_r_jtXopdich) cluster1(r) cluster2(jt)
outreg2 using "${dir_output_table}/Table5a", tex(frag) se keep(lntotalemploy_rjt lntotalemploy_rjtXopdich) label replace

bencgmivreg bribe_pctrev opdich i.t i.rj, endog(lntotalemploy_rjt lntotalemploy_rjtXopdich lntotalemploy_rjtXlnemployj) instr(lntotalemploy_r_jt lntotalemploy_r_jtXopdich lntotalemploy_r_jtXlnemployj) cluster1(r) cluster2(jt)
outreg2 using "${dir_output_table}/Table5a", tex(frag) se keep(lntotalemploy_rjt lntotalemploy_rjtXopdich) label append

****Multiple VN IV
bencgmivreg bribe_pctrev opdich i.t i.rj,endog(lntotalemploy_rjt lntotalemploy_rjtXopdich) instr(lntotalemploy_r_jtXinddummy1-lntotalemploy_r_jtXinddummy18 VNXopdichXinddummy1-VNXopdichXinddummy18) cluster1(r) cluster2(jt)
outreg2 using "${dir_output_table}/Table5a", tex(frag) se keep(lntotalemploy_rjt lntotalemploy_rjtXopdich) label append

bencgmivreg bribe_pctrev opdich i.t i.rj,endog(lntotalemploy_rjt lntotalemploy_rjtXopdich lntotalemploy_rjtXlnemployj) instr(lntotalemploy_r_jtXinddummy1-lntotalemploy_r_jtXinddummy18 VNXopdichXinddummy1-VNXopdichXinddummy18 VNXlnemployjXinddummy1-VNXlnemployjXinddummy18) cluster1(r) cluster2(jt)
outreg2 using "${dir_output_table}/Table5a", tex(frag) se keep(lntotalemploy_rjt lntotalemploy_rjtXopdich) label append

****Single Chinese IV
bencgmivreg bribe_pctrev opdich i.t i.rj,endog(lntotalemploy_rjt lntotalemploy_rjtXopdich) instr(lnchtotalemploy_jt lnchtotalemploy_jtXopdich) cluster1(r) cluster2(jt)
outreg2 using "${dir_output_table}/Table5b", tex(frag) se keep(lntotalemploy_rjt lntotalemploy_rjtXopdich) label replace

bencgmivreg bribe_pctrev opdich i.t i.rj, endog(lntotalemploy_rjt lntotalemploy_rjtXopdich lntotalemploy_rjtXlnemployj) instr(lnchtotalemploy_jt lnchtotalemploy_jtXopdich lnchtotalemploy_jtXlnemployj) cluster1(r) cluster2(jt)
outreg2 using "${dir_output_table}/Table5b", tex(frag) se keep(lntotalemploy_rjt lntotalemploy_rjtXopdich) label append
	
****Multiple Chinese IV
bencgmivreg bribe_pctrev opdich i.t i.rj,endog(lntotalemploy_rjt lntotalemploy_rjtXopdich) instr(lnchtotalemploy_jtXinddummy1-lnchtotalemploy_jtXinddummy18 chXopdichXinddummy1-chXopdichXinddummy18) cluster1(r) cluster2(jt)
outreg2 using "${dir_output_table}/Table5b", tex(frag) se keep(lntotalemploy_rjt lntotalemploy_rjtXopdich) label append

bencgmivreg bribe_pctrev opdich i.t i.rj,endog(lntotalemploy_rjt lntotalemploy_rjtXopdich lntotalemploy_rjtXlnemployj) instr(lnchtotalemploy_jtXinddummy1-lnchtotalemploy_jtXinddummy18 chXopdichXinddummy1-chXopdichXinddummy18 chXlnemployjXinddummy1-chXlnemployjXinddummy18) cluster1(r) cluster2(jt)
outreg2 using "${dir_output_table}/Table5b", tex(frag) se keep(lntotalemploy_rjt lntotalemploy_rjtXopdich) label append



********** Table A1: Cross validation **********

set more off

use "${dir_data_analysis}/crossvalidation_2digit_exclude10",clear

label var ln_mean_employ "Log VN mean in GSO"
label var ln_med_employ "Log VN median in GSO"

xi: areg  ln_mean_employ_pci ln_mean_employ i.t, absorb(rb) cluster(pci_id)
est store a2_1
xi: areg  ln_med_employ_pci ln_med_employ i.t, absorb(rb) cluster(pci_id)
est store a2_2

use "${dir_data_analysis}/crossvalidation_2digit_allfirms",clear

label var ln_mean_employ "Log VN mean in GSO"
label var ln_med_employ "Log VN median in GSO"

xi: areg  ln_mean_employ_pci ln_mean_employ i.t, absorb(rb) cluster(pci_id)
est store a2_3
xi: areg  ln_med_employ_pci ln_med_employ i.t, absorb(rb) cluster(pci_id)
est store a2_4


tempname texfile
file open `texfile' using "${dir_output_table}/TableA1", write replace 
file close `texfile'

estout a2_1 a2_2 a2_3 a2_4 /// 
	using "${dir_output_table}/TableA1", cells(b(star fmt(%9.3f)) se(par)) ///
	starlevels( * 0.10 ** 0.05 *** 0.010) stats(N, fmt(%3.0f) labels(Observations)) mlabels(,none) label ///
	keep(ln_mean_employ ln_med_employ) ///
	style(tex) collabels(none) eqlabels(none) append


********** Table A3: First Stage: Multiple IVs **********

set more off

use "${dir_data_analysis}/GSO_IV",clear

sort broad year

merge m:1 broad year using "${dir_data_original}/CH_YLS_0612"
keep if _m==3
drop _m

label var lntotalemploy_r_jt "Log Vietnamese employment in industry-year (excluding own province)"
label var lnchtotalemploy_jt "Log Chinese employment in industry-year"

tab j,g(inddummy)
forvalues i=1(1)18{
	g lntotalemploy_r_jtXinddummy`i'=lntotalemploy_r_jt*inddummy`i'
	label var lntotalemploy_r_jtXinddummy`i' "industry`i'"
	}

forvalues i=1(1)18{
	g lnchtotalemploy_jtXinddummy`i'=lnchtotalemploy_jt*inddummy`i'
	label var lnchtotalemploy_jtXinddummy`i' "industry`i'"
	}

xi: areg lntotalemploy_rjt lntotalemploy_r_jtXinddummy1-lntotalemploy_r_jtXinddummy18 i.t, absorb(rj) cluster(r)
testparm lntotalemploy_r_jtXinddummy1-lntotalemploy_r_jtXinddummy18 
local fstats=r(F)
	
xi: bencgmareg lntotalemploy_rjt lntotalemploy_r_jtXinddummy1-lntotalemploy_r_jtXinddummy18 i.t, absorb(rj) cluster1(r) cluster2(jt)
outreg2 using "${dir_output_table}/TableA3", adds(F-stats,`fstats') tex(frag) se keep(lntotalemploy_r_jtXinddummy1-lntotalemploy_r_jtXinddummy18) label replace

xi: areg lntotalemploy_rjt lnchtotalemploy_jtXinddummy1-lnchtotalemploy_jtXinddummy18 i.t, absorb(rj) cluster(r)
testparm lnchtotalemploy_jtXinddummy1-lnchtotalemploy_jtXinddummy18 
local fstats=r(F)

xi: bencgmareg lntotalemploy_rjt lnchtotalemploy_jtXinddummy1-lnchtotalemploy_jtXinddummy18 i.t, absorb(rj) cluster1(r) cluster2(jt)
outreg2 using "${dir_output_table}/TableA3", adds(F-stats,`fstats') tex(frag) se keep(lnchtotalemploy_jtXinddummy1-lnchtotalemploy_jtXinddummy18) label append



********** Table A4: Main Results (All Firms) **********

set more off

use "${dir_data_analysis}/finalanalysissample_allfirms",clear

***Vietnam

//Single IV
bencgmivreg bribe_pctrev i.t i.rj ,endog(lntotalemploy_rjt) instr(lntotalemploy_r_jt) cluster1(r) cluster2(jt)
outreg2 using "${dir_output_table}/TableA4a", tex(frag) se keep(lntotalemploy_rjt) label replace

//Multiple IV
bencgmivreg bribe_pctrev i.t i.rj ,endog(lntotalemploy_rjt) instr(lntotalemploy_r_jtXinddummy1-lntotalemploy_r_jtXinddummy18) cluster1(r) cluster2(jt)
outreg2 using "${dir_output_table}/TableA4a", tex(frag) se keep(lntotalemploy_rjt) label append

//Reduced form: OLS
xi: bencgmareg bribe_pctrev lntotalemploy_r_jt i.t , absorb(rj) cluster1(r) cluster2(jt)
outreg2 using "${dir_output_table}/TableA4a", tex(frag) se keep(lntotalemploy_r_jt) label append

//Reduced form: Ordered probit
xi: bencgmoprobit bribe_pctrev lntotalemploy_r_jt i.t i.rj ,cluster1(r) cluster2(jt)
outreg2 using "${dir_output_table}/TableA4a", tex(frag) se keep(lntotalemploy_r_jt) label append


***China

//Single IV
bencgmivreg bribe_pctrev i.t i.rj ,endog(lntotalemploy_rjt) instr(lnchtotalemploy_jt) cluster1(r) cluster2(jt)
outreg2 using "${dir_output_table}/TableA4b", tex(frag) se keep(lntotalemploy_rjt) label replace

//Multiple IV
bencgmivreg bribe_pctrev i.t i.rj ,endog(lntotalemploy_rjt) instr(lnchtotalemploy_jtXinddummy1-lnchtotalemploy_jtXinddummy18) cluster1(r) cluster2(jt)
outreg2 using "${dir_output_table}/TableA4b", tex(frag) se keep(lntotalemploy_rjt) label append

//Reduced form: OLS
xi: bencgmareg bribe_pctrev lnchtotalemploy_jt i.t , absorb(rj) cluster1(r) cluster2(jt)
outreg2 using "${dir_output_table}/TableA4b", tex(frag) se keep(lnchtotalemploy_jt) label append

//Ordered probit
xi: bencgmoprobit bribe_pctrev lnchtotalemploy_jt i.t i.rj ,cluster1(r) cluster2(jt)
outreg2 using "${dir_output_table}/TableA4b", tex(frag) se keep(lnchtotalemploy_jt) label append


********** Table A5: Heterogeneous Effects on Property Rights (All Firms) **********

set more off

use "${dir_data_analysis}/finalanalysissample_allfirms",clear

***Single VN IV

bencgmivreg bribe_pctrev lurclastyr i.t i.rj,endog(lntotalemploy_rjt lntotalemploy_rjtXlurclastyr) instr(lntotalemploy_r_jt lntotalemploy_r_jtXlurclastyr) cluster1(r) cluster2(jt)
outreg2 using "${dir_output_table}/TableA5a", tex(frag) se keep(lntotalemploy_rjt lntotalemploy_rjtXlurclastyr) label replace

bencgmivreg bribe_pctrev i.t i.rj lurclastyr,endog(lntotalemploy_rjt lntotalemploy_rjtXlurclastyr lntotalemploy_rjtXlnemployj) instr(lntotalemploy_r_jt lntotalemploy_r_jtXlurclastyr lntotalemploy_r_jtXlnemployj) cluster1(r) cluster2(jt)
outreg2 using "${dir_output_table}/TableA5a", tex(frag) se keep(lntotalemploy_rjt lntotalemploy_rjtXlurclastyr) label append

bencgmivreg bribe_pctrev ownland lurclastyr i.t i.rj,endog(lntotalemploy_rjt lntotalemploy_rjtXownland lntotalemploy_rjtXlurclastyr) instr(lntotalemploy_r_jt lntotalemploy_r_jtXownland lntotalemploy_r_jtXlurclastyr) cluster1(r) cluster2(jt)
outreg2 using "${dir_output_table}/TableA5a", tex(frag) se keep(lntotalemploy_rjt lntotalemploy_rjtXlurclastyr lntotalemploy_rjtXownland) label append

bencgmivreg bribe_pctrev ownland lurclastyr i.t i.rj, endog(lntotalemploy_rjt lntotalemploy_rjtXownland lntotalemploy_rjtXlurclastyr lntotalemploy_rjtXlnemployj) instr(lntotalemploy_r_jt lntotalemploy_r_jtXownland lntotalemploy_r_jtXlurclastyr lntotalemploy_r_jtXlnemployj) cluster1(r) cluster2(jt)
outreg2 using "${dir_output_table}/TableA5a", tex(frag) se keep(lntotalemploy_rjt lntotalemploy_rjtXlurclastyr lntotalemploy_rjtXownland) label append


***Multiple VN IV

bencgmivreg bribe_pctrev lurclastyr i.t i.rj, endog(lntotalemploy_rjt lntotalemploy_rjtXlurclastyr) instr(lntotalemploy_r_jtXinddummy1-lntotalemploy_r_jtXinddummy18 VNXlurclastyrXinddummy1-VNXlurclastyrXinddummy18) cluster1(r) cluster2(jt)
outreg2 using "${dir_output_table}/TableA5a", tex(frag) se keep(lntotalemploy_rjt lntotalemploy_rjtXlurclastyr) label append

bencgmivreg bribe_pctrev lurclastyr i.t i.rj, endog(lntotalemploy_rjt lntotalemploy_rjtXlurclastyr lntotalemploy_rjtXlnemployj) instr(lntotalemploy_r_jtXinddummy1-lntotalemploy_r_jtXinddummy18 VNXlurclastyrXinddummy1-VNXlurclastyrXinddummy18 VNXlnemployjXinddummy1-VNXlnemployjXinddummy18) cluster1(r) cluster2(jt)
outreg2 using "${dir_output_table}/TableA5a", tex(frag) se keep(lntotalemploy_rjt lntotalemploy_rjtXlurclastyr) label append

bencgmivreg bribe_pctrev ownland lurclastyr i.t i.rj,endog(lntotalemploy_rjt lntotalemploy_rjtXownland lntotalemploy_rjtXlurclastyr) instr(lntotalemploy_r_jtXinddummy1-lntotalemploy_r_jtXinddummy18 VNXownlandXinddummy1-VNXownlandXinddummy18 VNXlurclastyrXinddummy1-VNXlurclastyrXinddummy18) cluster1(r) cluster2(jt)
outreg2 using "${dir_output_table}/TableA5a", tex(frag) se keep(lntotalemploy_rjt lntotalemploy_rjtXlurclastyr lntotalemploy_rjtXownland) label append

bencgmivreg bribe_pctrev ownland lurclastyr i.t i.rj,endog(lntotalemploy_rjt lntotalemploy_rjtXownland lntotalemploy_rjtXlurclastyr lntotalemploy_rjtXlnemployj) instr(lntotalemploy_r_jtXinddummy1-lntotalemploy_r_jtXinddummy18 VNXownlandXinddummy1-VNXownlandXinddummy18 VNXlurclastyrXinddummy1-VNXlurclastyrXinddummy18 VNXlnemployjXinddummy1-VNXlnemployjXinddummy18) cluster1(r) cluster2(jt)
outreg2 using "${dir_output_table}/TableA5a", tex(frag) se keep(lntotalemploy_rjt lntotalemploy_rjtXlurclastyr lntotalemploy_rjtXownland) label append


***Single Chinese IV

bencgmivreg bribe_pctrev lurclastyr i.t i.rj,endog(lntotalemploy_rjt lntotalemploy_rjtXlurclastyr) instr(lnchtotalemploy_jt lnchtotalemploy_jtXlurclastyr) cluster1(r) cluster2(jt)
outreg2 using "${dir_output_table}/TableA5b", tex(frag) se keep(lntotalemploy_rjt lntotalemploy_rjtXlurclastyr) label replace

bencgmivreg bribe_pctrev i.t i.rj lurclastyr,endog(lntotalemploy_rjt lntotalemploy_rjtXlurclastyr lntotalemploy_rjtXlnemployj) instr(lnchtotalemploy_jt lnchtotalemploy_jtXlurclastyr lnchtotalemploy_jtXlnemployj) cluster1(r) cluster2(jt)
outreg2 using "${dir_output_table}/TableA5b", tex(frag) se keep(lntotalemploy_rjt lntotalemploy_rjtXlurclastyr) label append

bencgmivreg bribe_pctrev ownland lurclastyr i.t i.rj,endog(lntotalemploy_rjt lntotalemploy_rjtXownland lntotalemploy_rjtXlurclastyr) instr(lnchtotalemploy_jt lnchtotalemploy_jtXownland lnchtotalemploy_jtXlurclastyr) cluster1(r) cluster2(jt)
outreg2 using "${dir_output_table}/TableA5b", tex(frag) se keep(lntotalemploy_rjt lntotalemploy_rjtXlurclastyr lntotalemploy_rjtXownland) label append

bencgmivreg bribe_pctrev ownland lurclastyr i.t i.rj, endog(lntotalemploy_rjt lntotalemploy_rjtXownland lntotalemploy_rjtXlurclastyr lntotalemploy_rjtXlnemployj) instr(lnchtotalemploy_jt lnchtotalemploy_jtXownland lnchtotalemploy_jtXlurclastyr lnchtotalemploy_jtXlnemployj) cluster1(r) cluster2(jt)
outreg2 using "${dir_output_table}/TableA5b", tex(frag) se keep(lntotalemploy_rjt lntotalemploy_rjtXlurclastyr lntotalemploy_rjtXownland) label append

	
***Multiple Chinese IV

bencgmivreg bribe_pctrev lurclastyr i.t i.rj, endog(lntotalemploy_rjt lntotalemploy_rjtXlurclastyr) instr(lnchtotalemploy_jtXinddummy1-lnchtotalemploy_jtXinddummy18 chXlurclastyrXinddummy1-chXlurclastyrXinddummy18) cluster1(r) cluster2(jt)
outreg2 using "${dir_output_table}/TableA5b", tex(frag) se keep(lntotalemploy_rjt lntotalemploy_rjtXlurclastyr) label append

bencgmivreg bribe_pctrev lurclastyr i.t i.rj, endog(lntotalemploy_rjt lntotalemploy_rjtXlurclastyr lntotalemploy_rjtXlnemployj) instr(lnchtotalemploy_jtXinddummy1-lnchtotalemploy_jtXinddummy18 chXlurclastyrXinddummy1-chXlurclastyrXinddummy18 chXlnemployjXinddummy1-chXlnemployjXinddummy18) cluster1(r) cluster2(jt)
outreg2 using "${dir_output_table}/TableA5b", tex(frag) se keep(lntotalemploy_rjt lntotalemploy_rjtXlurclastyr) label append

bencgmivreg bribe_pctrev ownland lurclastyr i.t i.rj,endog(lntotalemploy_rjt lntotalemploy_rjtXownland lntotalemploy_rjtXlurclastyr) instr(lnchtotalemploy_jtXinddummy1-lnchtotalemploy_jtXinddummy18 chXownlandXinddummy1-chXownlandXinddummy18 chXlurclastyrXinddummy1-chXlurclastyrXinddummy18) cluster1(r) cluster2(jt)
outreg2 using "${dir_output_table}/TableA5b", tex(frag) se keep(lntotalemploy_rjt lntotalemploy_rjtXlurclastyr lntotalemploy_rjtXownland) label append

bencgmivreg bribe_pctrev ownland lurclastyr i.t i.rj,endog(lntotalemploy_rjt lntotalemploy_rjtXownland lntotalemploy_rjtXlurclastyr lntotalemploy_rjtXlnemployj) instr(lnchtotalemploy_jtXinddummy1-lnchtotalemploy_jtXinddummy18 chXownlandXinddummy1-chXownlandXinddummy18 chXlurclastyrXinddummy1-chXlurclastyrXinddummy18 chXlnemployjXinddummy1-chXlnemployjXinddummy18) cluster1(r) cluster2(jt)
outreg2 using "${dir_output_table}/TableA5b", tex(frag) se keep(lntotalemploy_rjt lntotalemploy_rjtXlurclastyr lntotalemploy_rjtXownland) label append



********** Table A6: Heterogeneous Effects on Operation Location (All Firms) **********

set more off

use "${dir_data_analysis}/finalanalysissample_allfirms",clear

****Single VN IV
bencgmivreg bribe_pctrev opdich i.t i.rj,endog(lntotalemploy_rjt lntotalemploy_rjtXopdich) instr(lntotalemploy_r_jt lntotalemploy_r_jtXopdich) cluster1(r) cluster2(jt)
outreg2 using "${dir_output_table}/TableA6a", tex(frag) se keep(lntotalemploy_rjt lntotalemploy_rjtXopdich) label replace

bencgmivreg bribe_pctrev opdich i.t i.rj, endog(lntotalemploy_rjt lntotalemploy_rjtXopdich lntotalemploy_rjtXlnemployj) instr(lntotalemploy_r_jt lntotalemploy_r_jtXopdich lntotalemploy_r_jtXlnemployj) cluster1(r) cluster2(jt)
outreg2 using "${dir_output_table}/TableA6a", tex(frag) se keep(lntotalemploy_rjt lntotalemploy_rjtXopdich) label append

****Multiple VN IV
bencgmivreg bribe_pctrev opdich i.t i.rj,endog(lntotalemploy_rjt lntotalemploy_rjtXopdich) instr(lntotalemploy_r_jtXinddummy1-lntotalemploy_r_jtXinddummy18 VNXopdichXinddummy1-VNXopdichXinddummy18) cluster1(r) cluster2(jt)
outreg2 using "${dir_output_table}/TableA6a", tex(frag) se keep(lntotalemploy_rjt lntotalemploy_rjtXopdich) label append

bencgmivreg bribe_pctrev opdich i.t i.rj,endog(lntotalemploy_rjt lntotalemploy_rjtXopdich lntotalemploy_rjtXlnemployj) instr(lntotalemploy_r_jtXinddummy1-lntotalemploy_r_jtXinddummy18 VNXopdichXinddummy1-VNXopdichXinddummy18 VNXlnemployjXinddummy1-VNXlnemployjXinddummy18) cluster1(r) cluster2(jt)
outreg2 using "${dir_output_table}/TableA6a", tex(frag) se keep(lntotalemploy_rjt lntotalemploy_rjtXopdich) label append

****Single Chinese IV
bencgmivreg bribe_pctrev opdich i.t i.rj,endog(lntotalemploy_rjt lntotalemploy_rjtXopdich) instr(lnchtotalemploy_jt lnchtotalemploy_jtXopdich) cluster1(r) cluster2(jt)
outreg2 using "${dir_output_table}/TableA6b", tex(frag) se keep(lntotalemploy_rjt lntotalemploy_rjtXopdich) label replace

bencgmivreg bribe_pctrev opdich i.t i.rj, endog(lntotalemploy_rjt lntotalemploy_rjtXopdich lntotalemploy_rjtXlnemployj) instr(lnchtotalemploy_jt lnchtotalemploy_jtXopdich lnchtotalemploy_jtXlnemployj) cluster1(r) cluster2(jt)
outreg2 using "${dir_output_table}/TableA6b", tex(frag) se keep(lntotalemploy_rjt lntotalemploy_rjtXopdich) label append
	
****Multiple Chinese IV
bencgmivreg bribe_pctrev opdich i.t i.rj,endog(lntotalemploy_rjt lntotalemploy_rjtXopdich) instr(lnchtotalemploy_jtXinddummy1-lnchtotalemploy_jtXinddummy18 chXopdichXinddummy1-chXopdichXinddummy18) cluster1(r) cluster2(jt)
outreg2 using "${dir_output_table}/TableA6b", tex(frag) se keep(lntotalemploy_rjt lntotalemploy_rjtXopdich) label append

bencgmivreg bribe_pctrev opdich i.t i.rj,endog(lntotalemploy_rjt lntotalemploy_rjtXopdich lntotalemploy_rjtXlnemployj) instr(lnchtotalemploy_jtXinddummy1-lnchtotalemploy_jtXinddummy18 chXopdichXinddummy1-chXopdichXinddummy18 chXlnemployjXinddummy1-chXlnemployjXinddummy18) cluster1(r) cluster2(jt)
outreg2 using "${dir_output_table}/TableA6b", tex(frag) se keep(lntotalemploy_rjt lntotalemploy_rjtXopdich) label append



********** Table A7: Robustness Check: Rest-of-Region IV **********

use "${dir_data_analysis}/finalanalysissample",clear

drop if employ_lag==.b & employ==.b
keep if (employ_lag>2 & employ_lag!=.b) | (employ_lag==.b & employ>2 & yrsopen>0 & yrsopen!=.)

xi: bencgmareg bribe_pctrev lntotalemploy_reg_jt i.t, absorb(rj) cluster1(r) cluster2(jt)
outreg2 using "${dir_output_table}/TableA7", tex(frag) se keep(lntotalemploy_reg_jt) label replace

	
********** Table A8: Plausibly Exogenous IV **********
set more off
use "${dir_data_analysis}/finalanalysissample",clear

drop if employ_lag==.b & employ==.b
keep if (employ_lag>2 & employ_lag!=.b) | (employ_lag==.b & employ>2 & yrsopen>0 & yrsopen!=.)
	
tab t,g(dummyyear)
tab rj,g(dummyrj)

***Main spec
bencgmivreg bribe_pctrev i.t i.rj ,endog(lntotalemploy_rjt) instr(lntotalemploy_r_jt) cluster1(r) cluster2(jt)

***Clustering at jt
ivreg bribe_pctrev dummyyear1-dummyyear5 dummyrj1-dummyrj620 (lntotalemploy_rjt=lntotalemploy_r_jt), cluster(jt)

//delta=0.05
plausexog uci bribe_pctrev dummyyear1-dummyyear5 dummyrj2-dummyrj620 ///
	(lntotalemploy_rjt=lntotalemploy_r_jt), gmin(-0.17) gmax(0.17) vce(cluster jt) level (0.95)

//delta=0.1
plausexog uci bribe_pctrev dummyyear1-dummyyear5 dummyrj2-dummyrj620 ///
	(lntotalemploy_rjt=lntotalemploy_r_jt), gmin(-0.34) gmax(0.34) vce(cluster jt) level (0.95)

//delta=0.15
plausexog uci bribe_pctrev dummyyear1-dummyyear5 dummyrj2-dummyrj620 ///
	(lntotalemploy_rjt=lntotalemploy_r_jt), gmin(-0.51) gmax(0.51) vce(cluster jt) level (0.95)

//delta=0.3
plausexog uci bribe_pctrev dummyyear1-dummyyear5 dummyrj2-dummyrj620 ///
	(lntotalemploy_rjt=lntotalemploy_r_jt), gmin(-1.02) gmax(1.02) vce(cluster jt) level (0.95)

//delta=0.5
plausexog uci bribe_pctrev dummyyear1-dummyyear5 dummyrj2-dummyrj620 ///
	(lntotalemploy_rjt=lntotalemploy_r_jt), gmin(-1.7) gmax(1.7) vce(cluster jt) level (0.95)


***Clustering at r
ivreg bribe_pctrev dummyyear1-dummyyear5 dummyrj1-dummyrj620 (lntotalemploy_rjt=lntotalemploy_r_jt), cluster(r)

//delta=0.05
plausexog uci bribe_pctrev dummyyear1-dummyyear5 dummyrj2-dummyrj620 ///
	(lntotalemploy_rjt=lntotalemploy_r_jt), gmin(-0.17) gmax(0.17) vce(cluster r) level (0.95)

//delta=0.1
plausexog uci bribe_pctrev dummyyear1-dummyyear5 dummyrj2-dummyrj620 ///
	(lntotalemploy_rjt=lntotalemploy_r_jt), gmin(-0.34) gmax(0.34) vce(cluster r) level (0.95)

//delta=0.15
plausexog uci bribe_pctrev dummyyear1-dummyyear5 dummyrj2-dummyrj620 ///
	(lntotalemploy_rjt=lntotalemploy_r_jt), gmin(-0.51) gmax(0.51) vce(cluster r) level (0.95)

//delta=0.3
plausexog uci bribe_pctrev dummyyear1-dummyyear5 dummyrj2-dummyrj620 ///
	(lntotalemploy_rjt=lntotalemploy_r_jt), gmin(-1.02) gmax(1.02) vce(cluster r) level (0.95)

//delta=0.5
plausexog uci bribe_pctrev dummyyear1-dummyyear5 dummyrj2-dummyrj620 ///
	(lntotalemploy_rjt=lntotalemploy_r_jt), gmin(-1.7) gmax(1.7) vce(cluster r) level (0.95)

	
	
********** Table A9: Contemporaneous LURC **********
set more off
use "${dir_data_analysis}/finalanalysissample",clear

drop if employ_lag==.b & employ==.b
keep if (employ_lag>2 & employ_lag!=.b) | (employ_lag==.b & employ>2 & yrsopen>0 & yrsopen!=.)

***Single VN IV

bencgmivreg bribe_pctrev lurc i.t i.rj,endog(lntotalemploy_rjt lntotalemploy_rjtXlurc) instr(lntotalemploy_r_jt lntotalemploy_r_jtXlurc) cluster1(r) cluster2(jt)
outreg2 using "${dir_output_table}/TableA9", tex(frag) se keep(lntotalemploy_rjt lntotalemploy_rjtXlurc lurc) label replace

bencgmivreg bribe_pctrev lurc i.t i.rj,endog(lntotalemploy_rjt lntotalemploy_rjtXlurc lntotalemploy_rjtXlnemployj) instr(lntotalemploy_r_jt lntotalemploy_r_jtXlurc lntotalemploy_r_jtXlnemployj) cluster1(r) cluster2(jt)
outreg2 using "${dir_output_table}/TableA9", tex(frag) se keep(lntotalemploy_rjt lntotalemploy_rjtXlurc lurc) label append

bencgmivreg bribe_pctrev ownland lurc i.t i.rj,endog(lntotalemploy_rjt lntotalemploy_rjtXownland lntotalemploy_rjtXlurc) instr(lntotalemploy_r_jt lntotalemploy_r_jtXownland lntotalemploy_r_jtXlurc) cluster1(r) cluster2(jt)
outreg2 using "${dir_output_table}/TableA9", tex(frag) se keep(lntotalemploy_rjt lntotalemploy_rjtXlurc lurc lntotalemploy_rjtXownland ownland) label append

bencgmivreg bribe_pctrev ownland lurc i.t i.rj,endog(lntotalemploy_rjt lntotalemploy_rjtXownland lntotalemploy_rjtXlurc lntotalemploy_rjtXlnemployj) instr(lntotalemploy_r_jt lntotalemploy_r_jtXownland lntotalemploy_r_jtXlurc lntotalemploy_r_jtXlnemployj) cluster1(r) cluster2(jt)
outreg2 using "${dir_output_table}/TableA9", tex(frag) se keep(lntotalemploy_rjt lntotalemploy_rjtXlurc lurc lntotalemploy_rjtXownland ownland) label append

	
***Multiple Ch IV

bencgmivreg bribe_pctrev lurc i.t i.rj, endog(lntotalemploy_rjt lntotalemploy_rjtXlurc) instr(lnchtotalemploy_jtXinddummy1-lnchtotalemploy_jtXinddummy18 chXlurcXinddummy1-chXlurcXinddummy18) cluster1(r) cluster2(jt)
outreg2 using "${dir_output_table}/TableA9", tex(frag) se keep(lntotalemploy_rjt lntotalemploy_rjtXlurc lurc) label append

bencgmivreg bribe_pctrev lurc i.t i.rj, endog(lntotalemploy_rjt lntotalemploy_rjtXlurc lntotalemploy_rjtXlnemployj) instr(lnchtotalemploy_jtXinddummy1-lnchtotalemploy_jtXinddummy18 chXlurcXinddummy1-chXlurcXinddummy18 chXlnemployjXinddummy1-chXlnemployjXinddummy18) cluster1(r) cluster2(jt)
outreg2 using "${dir_output_table}/TableA9", tex(frag) se keep(lntotalemploy_rjt lntotalemploy_rjtXlurc lurc) label append

bencgmivreg bribe_pctrev ownland lurc i.t i.rj,endog(lntotalemploy_rjt lntotalemploy_rjtXownland lntotalemploy_rjtXlurc) instr(lnchtotalemploy_jtXinddummy1-lnchtotalemploy_jtXinddummy18 chXownlandXinddummy1-chXownlandXinddummy18 chXlurcXinddummy1-chXlurcXinddummy18) cluster1(r) cluster2(jt)
outreg2 using "${dir_output_table}/TableA9", tex(frag) se keep(lntotalemploy_rjt lntotalemploy_rjtXlurc lurc lntotalemploy_rjtXownland ownland) label append

bencgmivreg bribe_pctrev ownland lurc i.t i.rj,endog(lntotalemploy_rjt lntotalemploy_rjtXownland lntotalemploy_rjtXlurc lntotalemploy_rjtXlnemployj) instr(lnchtotalemploy_jtXinddummy1-lnchtotalemploy_jtXinddummy18 chXownlandXinddummy1-chXownlandXinddummy18 chXlurcXinddummy1-chXlurcXinddummy18 chXlnemployjXinddummy1-chXlnemployjXinddummy18) cluster1(r) cluster2(jt)
outreg2 using "${dir_output_table}/TableA9", tex(frag) se keep(lntotalemploy_rjt lntotalemploy_rjtXlurc lurc lntotalemploy_rjtXownland ownland) label append



********** Table A10: Ordered Probit **********

use "${dir_data_analysis}/finalanalysissample",clear
	
drop if employ_lag==.b & employ==.b
keep if (employ_lag>2 & employ_lag!=.b) | (employ_lag==.b & employ>2 & yrsopen>0 & yrsopen!=.)

xi: bencgmoprobit bribe_pctrev lntotalemploy_r_jt i.t i.rj if ownland==0,cluster1(r) cluster2(jt)
outreg2 using "${dir_output_table}/TableA10", tex(frag) se keep(lntotalemploy_r_jt) label replace

xi: bencgmoprobit bribe_pctrev lnchtotalemploy_jt i.t i.rj if ownland==0,cluster1(r) cluster2(jt)
outreg2 using "${dir_output_table}/TableA10", tex(frag) se keep(lnchtotalemploy_jt) label append

xi: bencgmoprobit bribe_pctrev lntotalemploy_r_jt i.t i.rj if ownlandnlc==1,cluster1(r) cluster2(jt)
outreg2 using "${dir_output_table}/TableA10", tex(frag) se keep(lntotalemploy_r_jt) label append

xi: bencgmoprobit bribe_pctrev lnchtotalemploy_jt i.t i.rj if ownlandnlc==1,cluster1(r) cluster2(jt)
outreg2 using "${dir_output_table}/TableA10", tex(frag) se keep(lnchtotalemploy_jt) label append

xi: bencgmoprobit bribe_pctrev lntotalemploy_r_jt i.t i.rj if ownland==1 & lurclastyr==1,cluster1(r) cluster2(jt)
outreg2 using "${dir_output_table}/TableA10", tex(frag) se keep(lntotalemploy_r_jt) label append

xi: bencgmoprobit bribe_pctrev lnchtotalemploy_jt i.t i.rj if ownland==1 & lurclastyr==1,cluster1(r) cluster2(jt)
outreg2 using "${dir_output_table}/TableA10", tex(frag) se keep(lnchtotalemploy_jt) label append

	
********** Table A11: Propoensity score regression **********

use "${dir_data_analysis}/finalanalysissample",clear

drop if employ_lag==.b & employ==.b
keep if (employ_lag>2 & employ_lag!=.b) | (employ_lag==.b & employ>2 & yrsopen>0 & yrsopen!=.)

logit lurclastyr sharedocs formerhhfirm formerSOE ownergov govholdshare lnprem pieces_d yrsopen  
est store propscorelurc

logit opdich sharedocs formerhhfirm formerSOE ownergov govholdshare lnprem pieces_d yrsopen  
est store propscoremprov

ologit operations sharedocs formerhhfirm formerSOE ownergov govholdshare lnprem pieces_d yrsopen  
est store propscoremprov2

tempname texfile
file open `texfile' using "${dir_output_table}/TableA11", write replace
file close `texfile' 

estout propscorelurc propscoremprov propscoremprov2 using "${dir_output_table}/TableA11", cells(b(star fmt(%9.3f)) se(par)) ///
	starlevels( * 0.10 ** 0.05 *** 0.010) stats(N, fmt(%9.0f) labels(Observations)) mlabels(,none) label ///
	keep(sharedocs formerhhfirm formerSOE ownergov govholdshare lnprem yrsopen ) ///
	style(tex) collabels(none) eqlabels(none) append 
	

	
********** Table A12 and A13: Robustness Checks for Property Rights Analysis **********
	
use "${dir_data_analysis}/finalanalysissample",clear
	
drop if employ_lag==.b & employ==.b
keep if (employ_lag>2 & employ_lag!=.b) | (employ_lag==.b & employ>2 & yrsopen>0 & yrsopen!=.)

***Single VN IV***

bencgmivreg bribe_pctrev ownland lurclastyr sharedocs i.t i.rj, ///
	endog(lntotalemploy_rjt lntotalemploy_rjtXlurclastyr lntotalemploy_rjtXownland lntotalemploy_rjtXlnemployj lntotalemploy_rjtXsharedocs) ///
	instr(lntotalemploy_r_jt lntotalemploy_r_jtXlurclastyr lntotalemploy_r_jtXownland lntotalemploy_r_jtXlnemployj lntotalemploy_r_jtXsharedocs) ///
	cluster1(r) cluster2(jt)	
outreg2 using "${dir_output_table}/TableA12a", tex(frag) se keep(lntotalemploy_rjt lntotalemploy_rjtXlurclastyr lntotalemploy_rjtXownland) label replace	
	
	
foreach v of var formerhhfirm formerSOE ownergov govholdshare ///
	lnprem yrsopen{
bencgmivreg bribe_pctrev ownland lurclastyr `v' i.t i.rj, ///
	endog(lntotalemploy_rjt lntotalemploy_rjtXlurclastyr lntotalemploy_rjtXownland lntotalemploy_rjtXlnemployj lntotalemploy_rjtX`v') ///
	instr(lntotalemploy_r_jt lntotalemploy_r_jtXlurclastyr lntotalemploy_r_jtXownland lntotalemploy_r_jtXlnemployj lntotalemploy_r_jtX`v') ///
	cluster1(r) cluster2(jt)	
outreg2 using "${dir_output_table}/TableA12a", tex(frag) se keep(lntotalemploy_rjt lntotalemploy_rjtXlurclastyr lntotalemploy_rjtXownland) label append
	}


bencgmivreg bribe_pctrev ownland lurclastyr plurclastyr pownland i.t i.rj, ///
	endog(lntotalemploy_rjt lntotalemploy_rjtXlurclastyr lntotalemploy_rjtXownland lntotalemploy_rjtXlnemployj lntotalemploy_rjtXplurclastyr lntotalemploy_rjtXpownland) ///
	instr(lntotalemploy_r_jt lntotalemploy_r_jtXlurclastyr lntotalemploy_r_jtXownland lntotalemploy_r_jtXlnemployj lntotalemploy_r_jtXplurclastyr lntotalemploy_r_jtXpownland) ///
	cluster1(r) cluster2(jt)	
outreg2 using "${dir_output_table}/TableA12a", tex(frag) se keep(lntotalemploy_rjt lntotalemploy_rjtXlurclastyr lntotalemploy_rjtXownland) label append


***Single Ch IV***
	
bencgmivreg bribe_pctrev ownland lurclastyr sharedocs i.t i.rj, ///
	endog(lntotalemploy_rjt lntotalemploy_rjtXlurclastyr lntotalemploy_rjtXownland lntotalemploy_rjtXlnemployj lntotalemploy_rjtXsharedocs) ///
	instr(lnchtotalemploy_jt lnchtotalemploy_jtXlurclastyr lnchtotalemploy_jtXownland lnchtotalemploy_jtXlnemployj lnchtotalemploy_jtXsharedocs) ///
	cluster1(r) cluster2(jt)	
outreg2 using "${dir_output_table}/TableA12b", tex(frag) se keep(lntotalemploy_rjt lntotalemploy_rjtXlurclastyr lntotalemploy_rjtXownland) label replace	
		

foreach v of var formerhhfirm formerSOE ownergov govholdshare ///
	lnprem yrsopen{
bencgmivreg bribe_pctrev ownland lurclastyr `v' i.t i.rj, ///
	endog(lntotalemploy_rjt lntotalemploy_rjtXlurclastyr lntotalemploy_rjtXownland lntotalemploy_rjtXlnemployj lntotalemploy_rjtX`v') ///
	instr(lnchtotalemploy_jt lnchtotalemploy_jtXlurclastyr lnchtotalemploy_jtXownland lnchtotalemploy_jtXlnemployj lnchtotalemploy_jtX`v') ///
	cluster1(r) cluster2(jt)	
outreg2 using "${dir_output_table}/TableA12b", tex(frag) se keep(lntotalemploy_rjt lntotalemploy_rjtXlurclastyr lntotalemploy_rjtXownland) label append
	}

bencgmivreg bribe_pctrev ownland lurclastyr plurclastyr pownland i.t i.rj, ///
	endog(lntotalemploy_rjt lntotalemploy_rjtXlurclastyr lntotalemploy_rjtXownland lntotalemploy_rjtXlnemployj lntotalemploy_rjtXplurclastyr lntotalemploy_rjtXpownland) ///
	instr(lnchtotalemploy_jt lnchtotalemploy_jtXlurclastyr lnchtotalemploy_jtXownland lnchtotalemploy_jtXlnemployj lnchtotalemploy_jtXplurclastyr lnchtotalemploy_jtXpownland) ///
	cluster1(r) cluster2(jt)	
outreg2 using "${dir_output_table}/TableA12b", tex(frag) se keep(lntotalemploy_rjt lntotalemploy_rjtXlurclastyr lntotalemploy_rjtXownland) label append	


***Multiple VN IV***
	
bencgmivreg bribe_pctrev lurclastyr ownland sharedocs i.t i.rj, ///
	endog(lntotalemploy_rjt lntotalemploy_rjtXlurclastyr lntotalemploy_rjtXownland lntotalemploy_rjtXlnemployj lntotalemploy_rjtXsharedocs) ///
	instr(lntotalemploy_r_jtXinddummy1-lntotalemploy_r_jtXinddummy18 VNXlurclastyrXinddummy1-VNXlurclastyrXinddummy18 VNXownlandXinddummy1-VNXownlandXinddummy18 VNXlnemployjXinddummy1-VNXlnemployjXinddummy18 VNXsharedocsXinddummy1-VNXsharedocsXinddummy18) ///
	cluster1(r) cluster2(jt)
outreg2 using "${dir_output_table}/TableA13a", tex(frag) se keep(lntotalemploy_rjt lntotalemploy_rjtXlurclastyr lntotalemploy_rjtXownland) label replace	
	
	
foreach v of var formerhhfirm formerSOE ownergov govholdshare ///
	lnprem yrsopen{
bencgmivreg bribe_pctrev lurclastyr ownland `v' i.t i.rj, ///
	endog(lntotalemploy_rjt lntotalemploy_rjtXlurclastyr lntotalemploy_rjtXownland lntotalemploy_rjtXlnemployj lntotalemploy_rjtX`v') ///
	instr(lntotalemploy_r_jtXinddummy1-lntotalemploy_r_jtXinddummy18 VNXlurclastyrXinddummy1-VNXlurclastyrXinddummy18 VNXownlandXinddummy1-VNXownlandXinddummy18 VNXlnemployjXinddummy1-VNXlnemployjXinddummy18 VNX`v'Xinddummy1-VNX`v'Xinddummy18) ///
	cluster1(r) cluster2(jt)
outreg2 using "${dir_output_table}/TableA13a", tex(frag) se keep(lntotalemploy_rjt lntotalemploy_rjtXlurclastyr lntotalemploy_rjtXownland) label append

	}

bencgmivreg bribe_pctrev lurclastyr ownland plurclastyr pownland i.t i.rj, ///
	endog(lntotalemploy_rjt lntotalemploy_rjtXlurclastyr lntotalemploy_rjtXownland lntotalemploy_rjtXlnemployj lntotalemploy_rjtXplurclastyr lntotalemploy_rjtXpownland) ///
	instr(lntotalemploy_r_jtXinddummy1-lntotalemploy_r_jtXinddummy18 VNXlurclastyrXinddummy1-VNXlurclastyrXinddummy18 VNXownlandXinddummy1-VNXownlandXinddummy18 VNXlnemployjXinddummy1-VNXlnemployjXinddummy18 VNXplurclastyrXinddummy1-VNXplurclastyrXinddummy18 VNXpownlandXinddummy1-VNXpownlandXinddummy18) ///
	cluster1(r) cluster2(jt)
outreg2 using "${dir_output_table}/TableA13a", tex(frag) se keep(lntotalemploy_rjt lntotalemploy_rjtXlurclastyr lntotalemploy_rjtXownland) label append


***Multiple Ch IV***

bencgmivreg bribe_pctrev lurclastyr ownland sharedocs i.t i.rj, ///
	endog(lntotalemploy_rjt lntotalemploy_rjtXlurclastyr lntotalemploy_rjtXownland lntotalemploy_rjtXlnemployj lntotalemploy_rjtXsharedocs) ///
	instr(lnchtotalemploy_jtXinddummy1-lnchtotalemploy_jtXinddummy18 chXlurclastyrXinddummy1-chXlurclastyrXinddummy18 chXownlandXinddummy1-chXownlandXinddummy18 chXlnemployjXinddummy1-chXlnemployjXinddummy18 chXsharedocsXinddummy1-chXsharedocsXinddummy18) ///
	cluster1(r) cluster2(jt)
outreg2 using "${dir_output_table}/TableA13b", tex(frag) se keep(lntotalemploy_rjt lntotalemploy_rjtXlurclastyr lntotalemploy_rjtXownland) label replace	
	
foreach v of var formerhhfirm formerSOE ownergov govholdshare ///
	lnprem yrsopen{
bencgmivreg bribe_pctrev lurclastyr ownland `v' i.t i.rj, ///
	endog(lntotalemploy_rjt lntotalemploy_rjtXlurclastyr lntotalemploy_rjtXownland lntotalemploy_rjtXlnemployj lntotalemploy_rjtX`v') ///
	instr(lnchtotalemploy_jtXinddummy1-lnchtotalemploy_jtXinddummy18 chXlurclastyrXinddummy1-chXlurclastyrXinddummy18 chXownlandXinddummy1-chXownlandXinddummy18 chXlnemployjXinddummy1-chXlnemployjXinddummy18 chX`v'Xinddummy1-chX`v'Xinddummy18) ///
	cluster1(r) cluster2(jt)
outreg2 using "${dir_output_table}/TableA13b", tex(frag) se keep(lntotalemploy_rjt lntotalemploy_rjtXlurclastyr lntotalemploy_rjtXownland) label append
	}

bencgmivreg bribe_pctrev lurclastyr ownland plurclastyr pownland i.t i.rj, ///
	endog(lntotalemploy_rjt lntotalemploy_rjtXlurclastyr lntotalemploy_rjtXownland lntotalemploy_rjtXlnemployj lntotalemploy_rjtXplurclastyr lntotalemploy_rjtXpownland) ///
	instr(lnchtotalemploy_jtXinddummy1-lnchtotalemploy_jtXinddummy18 chXlurclastyrXinddummy1-chXlurclastyrXinddummy18 chXownlandXinddummy1-chXownlandXinddummy18 chXlnemployjXinddummy1-chXlnemployjXinddummy18 chXplurclastyrXinddummy1-chXplurclastyrXinddummy18 chXpownlandXinddummy1-chXpownlandXinddummy18) ///
	cluster1(r) cluster2(jt)
outreg2 using "${dir_output_table}/TableA13b", tex(frag) se keep(lntotalemploy_rjt lntotalemploy_rjtXlurclastyr lntotalemploy_rjtXownland) label append


********** Table A14 and A15: Robustness Checks for Operation Locations Analysis **********

use "${dir_data_analysis}/finalanalysissample",clear
	
drop if employ_lag==.b & employ==.b
keep if (employ_lag>2 & employ_lag!=.b) | (employ_lag==.b & employ>2 & yrsopen>0 & yrsopen!=.)

***Single VN IV***

bencgmivreg bribe_pctrev opdich sharedocs i.t i.rj,endog(lntotalemploy_rjt lntotalemploy_rjtXopdich lntotalemploy_rjtXlnemployj lntotalemploy_rjtXsharedocs) ///
	instr(lntotalemploy_r_jt lntotalemploy_r_jtXopdich lntotalemploy_r_jtXlnemployj lntotalemploy_r_jtXsharedocs) ///
	cluster1(r) cluster2(jt)
outreg2 using "${dir_output_table}/TableA14a", tex(frag) se keep(lntotalemploy_rjt lntotalemploy_rjtXopdich) label replace	

foreach v of var formerhhfirm formerSOE ownergov govholdshare ///
	lnprem yrsopen popdich{
bencgmivreg bribe_pctrev opdich `v' i.t i.rj,endog(lntotalemploy_rjt lntotalemploy_rjtXopdich lntotalemploy_rjtXlnemployj lntotalemploy_rjtX`v') ///
	instr(lntotalemploy_r_jt lntotalemploy_r_jtXopdich lntotalemploy_r_jtXlnemployj lntotalemploy_r_jtX`v') ///
	cluster1(r) cluster2(jt)
outreg2 using "${dir_output_table}/TableA14a", tex(frag) se keep(lntotalemploy_rjt lntotalemploy_rjtXopdich) label append	
	}	


***Single Ch IV***

bencgmivreg bribe_pctrev opdich sharedocs i.t i.rj,endog(lntotalemploy_rjt lntotalemploy_rjtXopdich lntotalemploy_rjtXlnemployj lntotalemploy_rjtXsharedocs) ///
	instr(lnchtotalemploy_jt lnchtotalemploy_jtXopdich lnchtotalemploy_jtXlnemployj lnchtotalemploy_jtXsharedocs) ///
	cluster1(r) cluster2(jt)
outreg2 using "${dir_output_table}/TableA14b", tex(frag) se keep(lntotalemploy_rjt lntotalemploy_rjtXopdich) label replace	

foreach v of var formerhhfirm formerSOE ownergov govholdshare ///
	lnprem yrsopen popdich{
bencgmivreg bribe_pctrev opdich `v' i.t i.rj,endog(lntotalemploy_rjt lntotalemploy_rjtXopdich lntotalemploy_rjtXlnemployj lntotalemploy_rjtX`v') ///
	instr(lnchtotalemploy_jt lnchtotalemploy_jtXopdich lnchtotalemploy_jtXlnemployj lnchtotalemploy_jtX`v') ///
	cluster1(r) cluster2(jt)
outreg2 using "${dir_output_table}/TableA14b", tex(frag) se keep(lntotalemploy_rjt lntotalemploy_rjtXopdich) label append	
	}	


***Multiple VN IV***

bencgmivreg bribe_pctrev opdich sharedocs i.t i.rj, ///
	endog(lntotalemploy_rjt lntotalemploy_rjtXopdich lntotalemploy_rjtXlnemployj lntotalemploy_rjtXsharedocs) ///
	instr(lntotalemploy_r_jtXinddummy1-lntotalemploy_r_jtXinddummy18 VNXopdichXinddummy1-VNXopdichXinddummy18 VNXlnemployjXinddummy1-VNXlnemployjXinddummy18 VNXsharedocsXinddummy1-VNXsharedocsXinddummy18) ///
	cluster1(r) cluster2(jt)
outreg2 using "${dir_output_table}/TableA15a", tex(frag) se keep(lntotalemploy_rjt lntotalemploy_rjtXopdich) label replace	

foreach v of var formerhhfirm formerSOE ownergov govholdshare ///
	lnprem yrsopen popdich{	
bencgmivreg bribe_pctrev opdich `v' i.t i.rj, ///
	endog(lntotalemploy_rjt lntotalemploy_rjtXopdich lntotalemploy_rjtXlnemployj lntotalemploy_rjtX`v') ///
	instr(lntotalemploy_r_jtXinddummy1-lntotalemploy_r_jtXinddummy18 VNXopdichXinddummy1-VNXopdichXinddummy18 VNXlnemployjXinddummy1-VNXlnemployjXinddummy18 VNX`v'Xinddummy1-VNX`v'Xinddummy18) ///
	cluster1(r) cluster2(jt)
outreg2 using "${dir_output_table}/TableA15a", tex(frag) se keep(lntotalemploy_rjt lntotalemploy_rjtXopdich) label append
	}
	
	
***Multiple Ch IV***

bencgmivreg bribe_pctrev opdich sharedocs i.t i.rj, ///
	endog(lntotalemploy_rjt lntotalemploy_rjtXopdich lntotalemploy_rjtXlnemployj lntotalemploy_rjtXsharedocs) ///
	instr(lnchtotalemploy_jtXinddummy1-lnchtotalemploy_jtXinddummy18 chXopdichXinddummy1-chXopdichXinddummy18 chXlnemployjXinddummy1-chXlnemployjXinddummy18 chXsharedocsXinddummy1-chXsharedocsXinddummy18) ///
	cluster1(r) cluster2(jt)
outreg2 using "${dir_output_table}/TableA15b", tex(frag) se keep(lntotalemploy_rjt lntotalemploy_rjtXopdich) label replace	

foreach v of var formerhhfirm formerSOE ownergov govholdshare ///
	lnprem yrsopen popdich{	
bencgmivreg bribe_pctrev opdich `v' i.t i.rj, ///
	endog(lntotalemploy_rjt lntotalemploy_rjtXopdich lntotalemploy_rjtXlnemployj lntotalemploy_rjtX`v') ///
	instr(lnchtotalemploy_jtXinddummy1-lnchtotalemploy_jtXinddummy18 chXopdichXinddummy1-chXopdichXinddummy18 chXlnemployjXinddummy1-chXlnemployjXinddummy18 chX`v'Xinddummy1-chX`v'Xinddummy18) ///
	cluster1(r) cluster2(jt)
outreg2 using "${dir_output_table}/TableA15b", tex(frag) se keep(lntotalemploy_rjt lntotalemploy_rjtXopdich) label append
	}
	
	
********** Table A16: Alternative Models ************

*** Industrial Herf***
set more off
use "${dir_data_analysis}/GSO_IVnoncollapsed.dta",clear

label var lntotalemploy_rjt "Log Vietnamese employment in industry-year (in own province)"

drop if employ==0
 
g share2=(employ/totalemploy_rjt)^2
bys rjt: egen herf_rjt=total(share2)

bys rjt: g N=_N
g herfn_rjt=(herf_rjt-1/N)/(1-1/N)  //normalize

bys rjt: g temp=_n
keep if temp==1

bencgmivreg herfn_rjt i.rj i.t,endog(lntotalemploy_rjt) instr(lntotalemploy_r_jt) cluster1(r) cluster2(jt)
outreg2 using "${dir_output_table}/TableA16", tex(frag) se keep(lntotalemploy_rjt) label replace	


*** Drop Construction industry
use "${dir_data_analysis}/finalanalysissample",clear
	
drop if employ_lag==.b & employ==.b
keep if (employ_lag>2 & employ_lag!=.b) | (employ_lag==.b & employ>2 & yrsopen>0 & yrsopen!=.)

label var lntotalemploy_rjt "Log Vietnamese employment in industry-year (in own province)"

drop if broad=="F"

bencgmivreg bribe_pctrev i.rj i.t, endog(lntotalemploy_rjt) instr(lntotalemploy_r_jt) cluster1(r) cluster2(jt)
outreg2 using "${dir_output_table}/TableA16", tex(frag) se keep(lntotalemploy_rjt) label append


*** Diminishing returns (using aggregate IV)
use "${dir_data_analysis}/finalanalysissample",clear
	
drop if employ_lag==.b & employ==.b
keep if (employ_lag>2 & employ_lag!=.b) | (employ_lag==.b & employ>2 & yrsopen>0 & yrsopen!=.)

g lntotalemploy_rt=ln(totalemploy_rt)

label var lntotalemploy_rjt "Log Vietnamese employment in industry-year (in own province)"
label var lntotalemploy_rt "Log Vietnamese province-year employment"

bencgmivreg bribe_pctrev i.rj i.t, endog(lntotalemploy_rjt lntotalemploy_rt) instr(lntotalemploy_r_jt lnIV_agg) cluster1(r) cluster2(jt)
outreg2 using "${dir_output_table}/TableA16", tex(frag) se keep(lntotalemploy_rjt lntotalemploy_rt) label append	

